﻿var isDocked;
function view_onOpen(){
	//Set default values
	options.putDefaultValue("chalkColor","FFFFFF");
	options.putDefaultValue("boardImg","stock_images\\green_board.png");
	options.putDefaultValue("descTxt","");
	options.putDefaultValue("current","0");
	options.putDefaultValue("Opacity", 100);
	//Get the saved options
	setChalkColor(options.getValue("chalkColor"));
	board.src=options.getValue("boardImg");
	desc_text.InnerText=options.getValue("descTxt");
  setOpacity(options.getValue("Opacity"));
	//set and get values and redraw if opening
	if (arguments.length>0){
		view_OnDock();
		plugin.onAddCustomMenuItems = AddCustomMenuItems;
	}
}

function view_OnDock(){
	isDocked=true;
	desc_text.visible=false;
	btn_holder.visible=false;
	counter.size=30;
	rearrange();
}
function view_onUnDock(){
	isDocked=false;
	desc_text.visible=true;
	btn_holder.visible=true;
	counter.size=10;
	rearrange();
}
/** Transparency **/
function AddCustomMenuItems(menu) {
  var opacSub = menu.AddPopup(TRANSP_LABEL);
  for (var i=100; i>10; i-=10) {
    var capt = i+"%";
    opacSub.AddItem(capt, (getOpacity()==i)?gddMenuItemFlagChecked:0, onOpacClicked);
  }
	menu.AddItem(COUNTER_OPT, 0, more);
}
function onOpacClicked(itemText) {
    var opac = itemText.substring(0, itemText.indexOf("%"));
    setOpacity(parseInt(opac));
		options.putValue("Opacity", opac);
}
function setOpacity(opac) {
  view_holder.opacity = (255/100)*opac;
}
function getOpacity() {
  var opac = view_holder.opacity/(255/100);
  opac = Math.round(opac);
  return opac;
}